DEFINITION MODULE WindowMgr;   (* Christoph Fleischer 24.01.85 *)
                               (* MacIntosh Toolbox Window Manager Routines *)
                               (* last modification   26.06.85 fxk *)
FROM SYSTEM IMPORT ADDRESS,ADR;
FROM MacBase IMPORT LongInt,Handle,StrPtr;
FROM EventMgr IMPORT EventRecord;
FROM QuickDraw IMPORT GrafPtr,GrafPort,RgnHandle,Point,Rect;

EXPORT QUALIFIED
    dialogKind,userKind,DocumentProc,DBoxProc,NoShadowDBox,RDocProc,inDesk,inMenuBar,inSysWindow,inContent,
    inDrag,inGrow,inGoAway,wNoHit,wInContent,wInDrag,wInGrow,wInGoAway,
    WindowPeek,WindowPtr,WindowRecord,WindowMessage,WindowProcPtr,
    InitWindows,GetWMgrPort,NewWindow,GetNewWindow,CloseWindow,DisposeWindow,
    SetWTitle,GetWTitle,SelectWindow,HideWindow,ShowWindow,ShowHide,ClipAbove,
    HiliteWindow,BringToFront,SendBehind,FrontWindow,DrawGrowIcon,FindWindow,
    TrackGoAway,MoveWindow,DragWindow,GrowWindow,SizeWindow,PaintOne,PaintBehind,
    SaveOld,DrawNew,CalcVis,CalcVisBehind,CheckUpdate,BeginUpdate,EndUpdate,
    SetWRefCon,GetWRefCon,SetWindowPic,GetWindowPic,ValidRect,ValidRgn,InvalRect,
    InvalRgn,PinRect,DragGrayRgn,GetWPeek;

CONST
  dialogKind   = 2; userKind     = 8;          (* types of windows *)
 
  DocumentProc = 0;          (* window definition procedure IDs *)
  DBoxProc     = 1;  NoShadowDBox = 2;  RDocProc     = 16;

  inDesk       = 0;          (* FindWindow Result Codes *)
  inMenuBar    = 1;  inSysWindow  = 2;  inContent    = 3;
  inDrag       = 4;  inGrow       = 5;  inGoAway     = 6;

  wNoHit       = 0;          (* defProc hit test codes *)
  wInContent   = 1;  wInDrag      = 2;  wInGrow      = 3;  wInGoAway    = 4;

TYPE
  StringHandle = POINTER TO StrPtr;
  Ptr          = ADDRESS;
  PicHandle    = ADDRESS;
  WindowPtr    = GrafPtr;
  WindowPeek   = POINTER TO WindowRecord;
  WindowRecord = RECORD
                   port:          GrafPort;
                   windowKind:    INTEGER;
                   visible:       BOOLEAN;
                   hilited:       BOOLEAN;
                   goAwayFlag:    BOOLEAN;
                   spareFlag:     BOOLEAN;
                   strucRgn:      RgnHandle;
                   contRgn:       RgnHandle;
                   updateRgn:     RgnHandle;
                   windowDefProc: Handle;
                   dataHandle:    Handle;
                   titleHandle:   StringHandle;
                   titleWidth:    INTEGER;
                   ControlList:   Handle;
                   nextWindow:    WindowPeek;
                   windowPic:     ADDRESS; (*PicHandle;*)
                   refCon:        LongInt;
                 END;

  WindowMessage = (wDraw, wHit, wCalcRgns, wNew, wDispose, wGrow, wDrawGIcon);
  WindowProcPtr = PROC;

PROCEDURE ClipAbove(window: WindowPeek);                      (*INLINE $A90B*)
PROCEDURE PaintOne(window: WindowPeek; clobbered: RgnHandle); (*INLINE $A90C*)
PROCEDURE PaintBehind(startWindow: WindowPeek; clobbered: RgnHandle);
                                                              (*INLINE $A90D*)
PROCEDURE SaveOld(window: WindowPeek);                        (*INLINE $A90E*)
PROCEDURE DrawNew(window: WindowPeek; fUpdate: BOOLEAN);      (*INLINE $A90F*)
PROCEDURE CalcVis(window: WindowPeek);                        (*INLINE $A909*)
PROCEDURE CalcVisBehind(startWindow: WindowPeek; clobbered: RgnHandle);
                                                              (*INLINE $A90A*)
PROCEDURE ShowHide(window: WindowPtr; showFlag: BOOLEAN);     (*INLINE $A908*)

PROCEDURE CheckUpdate(VAR theEvent: EventRecord): BOOLEAN;    (*INLINE $A911*)
PROCEDURE GetWMgrPort(VAR wPort: GrafPtr);                    (*INLINE $A910*)

PROCEDURE InitWindows;                                        (*INLINE $A912*)
PROCEDURE NewWindow(wStorage:       Ptr;
                    VAR boundsRect: Rect;
                    title:          StrPtr;
                    visible:        BOOLEAN;
                    theProc:        INTEGER;
                    behind:         WindowPtr;
                    goAwayFlag:     BOOLEAN;
                    refCon:         LongInt): WindowPtr;      (*INLINE $A913*)

PROCEDURE DisposeWindow (theWindow: WindowPtr);               (*INLINE $A914*)
PROCEDURE CloseWindow   (theWindow: WindowPtr);               (*INLINE $A92D*)
PROCEDURE MoveWindow    (theWindow: WindowPtr; h,v: INTEGER; BringToFront:BOOLEAN);
                                                              (*INLINE $A91B*)
PROCEDURE SizeWindow    (theWindow: WindowPtr; width,height: INTEGER; fUpdate: BOOLEAN);
                                                              (*INLINE $A91D*)
PROCEDURE GrowWindow    (theWindow: WindowPtr; startPt:Point;
                         VAR bBox: Rect): LongInt;            (*INLINE $A92B*)
PROCEDURE DragWindow    (theWindow: WindowPtr; startPt:Point;
                         VAR boundsRect: Rect);               (*INLINE $A925*)
PROCEDURE ShowWindow    (theWindow: WindowPtr);               (*INLINE $A915*)
PROCEDURE HideWindow    (theWindow: WindowPtr);               (*INLINE $A916*)
PROCEDURE SetWTitle     (theWindow: WindowPtr;title: StrPtr);(*INLINE $A91A*)
PROCEDURE GetWTitle     (theWindow: WindowPtr;title: StrPtr);(*INLINE $A919*)
PROCEDURE HiliteWindow  (theWindow: WindowPtr; fHiLite: BOOLEAN);(*INLINE $A91C*)
PROCEDURE BeginUpdate   (theWindow: WindowPtr);               (*INLINE $A922*)
PROCEDURE EndUpdate     (theWindow: WindowPtr);               (*INLINE $A923*)
PROCEDURE SetWRefCon    (theWindow: WindowPtr; data: LongInt);(*INLINE $A918*)
PROCEDURE GetWRefCon    (theWindow: WindowPtr): LongInt;      (*INLINE $A917*)
PROCEDURE SetWindowPic  (theWindow: WindowPtr; thePic: PicHandle);(*INLINE $A92E*)
PROCEDURE GetWindowPic  (theWindow: WindowPtr): PicHandle;    (*INLINE $A92F*)
PROCEDURE BringToFront  (theWindow: WindowPtr);               (*INLINE $A920*)
PROCEDURE SendBehind    (theWindow,behind: WindowPtr);        (*INLINE $A921*)
PROCEDURE FrontWindow(): WindowPtr;                         (*INLINE $A924*)
PROCEDURE SelectWindow  (theWindow: WindowPtr);               (*INLINE $A91F*)
PROCEDURE TrackGoAway   (theWindow: WindowPtr; thePoint:Point): BOOLEAN;
                                                              (*INLINE $A91E*)
PROCEDURE DrawGrowIcon  (theWindow: WindowPtr);               (*INLINE $A904*)

PROCEDURE ValidRect     (VAR goodRect: Rect);                 (*INLINE $A92A*)
PROCEDURE ValidRgn      (goodRgn: RgnHandle);                 (*INLINE $A929*)
PROCEDURE InvalRect     (VAR badRect: Rect);                  (*INLINE $A928*)
PROCEDURE InvalRgn      (badRgn:  RgnHandle);                 (*INLINE $A927*)
PROCEDURE FindWindow    (thePoint:Point;
                         VAR  theWindow: WindowPtr): INTEGER; (*INLINE $A92C*)
PROCEDURE GetNewWindow  (windowID: INTEGER; wStorage: Ptr;
                         behind: WindowPtr): WindowPtr;       (*INLINE $A9BD*)
PROCEDURE PinRect(VAR theRect: Rect; thePoint:Point): LongInt;  (*INLINE $A94E*)
PROCEDURE DragGrayRgn(theRgn: RgnHandle; startPt:Point; VAR boundsRect,
                      slopRect: Rect;axis: INTEGER;
                      actionProc: WindowProcPtr): LongInt;    (*INLINE $A905*)

(* This procedure finds the correspondent WindowPeek to a given WindowPtr *)
PROCEDURE GetWPeek(VAR wPointer: WindowPtr): WindowPeek;

END WindowMgr.
